<?php /*
@session_start();
 if((!isset($_SESSION["kt_login_id"]) && !isset($_SESSION["kt_login_user"]) &&  !isset($_SESSION["kt_login_level"])) ) {

    header("Location: login.php");
    exit;
	
}else{

$level = addslashes($_SESSION['kt_login_user']);
$user = addslashes($_SESSION['kt_login_level']);

echo $level;
echo $user;
}*/
require("classes/newsletter.class.php");
require_once("classes/util/utilitarios.class.php");

$newsletter 		= new Newsletter();
$utilitario 		= new Util();

$listNewsletter		= $newsletter->listNewsletterObject(); 
$campos 			= NULL;
$op 				= $_GET['op'];
$id 				= $_GET['id'];

if(empty($_GET)|| $op=='Add'){
	if(isset($_POST['action'])&& $_POST['action']=='Add')
	{
		foreach($_POST as $nome_campo => $valor){ 
		
		if($nome_campo=='footer'){
			$campos .= $nome_campo.",";//$valorNewsletter[$nome_campo] = $valor;
			$valores .= "'".htmlentities($valor)."',";//$valorNewsletter[$nome_campo] = $valor;
			
		}else{
			$campos .= $nome_campo.",";//$valorNewsletter[$nome_campo] = $valor;
			$valores .= "'".$valor."',";//$valorNewsletter[$nome_campo] = $valor;
		} 

		}
		$campos = substr_replace($campos,"",-15,15);
		$valores = substr_replace($valores,"",-16,16);
		echo $campos;
		echo $valores;
		$insert = $newsletter->addNewsletterFooter($campos,$valores);
		if(!$insert){
			$classe = "msgerror";
			$texto = "Error in the operation!";
		}else{
			$classe = "msgsucess";
			$texto = "Sucessfuly Executed!";
		}
	}
}elseif($op=='Update'){
	$update = mysql_fetch_assoc($newsletter->searchObjectFoo($id));
	print_r($update);
	if(isset($_POST['action'])&& $_POST['action']=='Update')
	{
	foreach($_POST as $nome_campo => $valor){ 
	
		if($nome_campo=='footer'){
			$valores .= $nome_campo."='".htmlentities($valor)."',";//$valorNewsletter[$nome_campo] = $valor;
			
		}else{
			$valores .= $nome_campo."='".$valor."',";//$valorNewsletter[$nome_campo] = $valor;
		}
			
		}
		
		$valores = substr_replace($valores,"",-33,33);
		//print_r($valores);
		$update_ = $newsletter->updateNewsletterContent($id,$valores);
		if(!$update_){
			$classe = "msgerror";
			$texto = "Error in the operation!";
		}else{
			$classe = "msgsucess";
			$texto = "Sucessfuly Executed!";
		}
	}
}elseif($op=='Delete'){
	$delete = $newsletter->removeNewsletterFooter($id);
	if(!$delete){
			$classe = "msgerror";
			$texto = "Error in the operation!";
		}else{
			$classe = "msgsucess";
			$texto = "Sucessfuly Executed!";
		}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user2.dwt.php" codeOutsideHTMLIsLocked="false" --><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>QS Controller</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEditableHeadTag -->
<!-- InstanceEndEditable -->
<style type="text/css" media="all">
<!--
@import url("css/basics.css");
-->
</style>
<!-- TinyMCE -->
<script type="text/javascript" src="includes/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript"
   src="includes/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
    	mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
theme_advanced_buttons1:
"code,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,cleanup,link,unlink,image,table",

		// Theme options
		theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect,forecolor,backcolor,fullscreen",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",


		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
	 content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
    file_browser_callback : "tinyBrowser",
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->

</head>
<body>
<div id="box">
<div id="topo">
<span>
<img src="images/logo.png" alt="QS Controller" width="293" height="112"  />
</span>
<p>Version: 1.0</p>
<p>Status: Beta </p>
<p><!-- InstanceBeginEditable name="logout" -->logout<!-- InstanceEndEditable --></p>

</div><!-- end div topo-->
<div id="menuhorizontal">
  <table width="500" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td><a href="index.php">Home</a></td>
       <td><a href="registered.php">People</a></td>
        <td><a href="newsletterList.php">Newsletter</a></td>
        
      <td><a href="statistics.php">Statistics</a></td>
    </tr>
  </table>


</div><!-- end div menuhorizontal -->

<div id="content">
<!-- InstanceBeginEditable name="content" -->  
 <div id="menudiv" >
<?php
$utilitario->menu('newsletter');
?>   
 </div><!-- end div submenu -->   
   
    <div class="KT_tng" >
      <h1> NEWSLETTER</h1>
        <?php
	  echo '
	  <div class="'.$classe.'" id="msgerror">
       '.$texto.'
      </div>';
	  ?>
      <?php 
	  
echo $err; 
	  
	  ?>
	  <div id="form">
	  <form name="addnewsletter" method="POST" action="">
	  <table width="382" border="0" cellspacing="2">
	    <tr>
	      <th colspan="2"><?php echo $op; ?> Newsletter Footer</th>
	      </tr>
         <tr>
	      <th colspan="2">Footer Information</th>
	      </tr>
	    <tr>
	      <td colspan="2"><?php echo'<textarea name="footer" id="resumo" cols="45" rows="5">'.$update['footer'].'</textarea>'; ?></td>
	      </tr>
	    <tr>
	      <th>Newsletter</th>
	      <td><select name="fk_newsletter" id="fk_newsletter">
	<option value="">Select</option>
		<?php	
			while($listNews =mysql_fetch_assoc($listNewsletter) ){
			if($update['fk_newsletter']==$listNews['ID']){
				echo '<option value="'.$listNews['ID'].'" selected="selected" >'."Ano: ".$listNews['ANO']." - No.: ".$listNews['NUMERO']." - Mês: ".$listNews['MES']." - Idioma: ".$listNews['IDIOMA'].'</option>\n';
			}else{
				
			
			
			echo '<option value="'.$listNews['ID'].'">'."Ano: ".$listNews['ANO']." - No.: ".$listNews['NUMERO']." - Mês: ".$listNews['MES']." - Idioma: ".$listNews['IDIOMA'].'</option>\n';}
			}
			
		?>
		
		
    </select></td>
	      </tr>
	    
	    <tr>
	      <td>&nbsp;</td>
	      <td><input name="action" type="hidden" value="<?php echo $op;?>" /><input type="submit" name="button" id="button" value="Submit" /></td>
	      </tr>
	    </table>
	  <p>&nbsp;</p>


   
   
      </form></div>
      </div><!-- InstanceEndEditable -->
</div><!-- end div content -->
</div> <!-- end div box -->

</body>
<!-- InstanceEnd --></html>
